package com.kotiln.lgc.sunnyweather.logic.model

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import com.kotiln.lgc.sunnyweather.logic.dao.Repository
import com.kotiln.lgc.sunnyweather.util.LogUtil

/**
 *@fileName WeatherViewModel
 *@date2020/12/1  18:01
 *@author WeatherViewModel$
 *@describe TODO
 *@desc
 */
class WeatherViewModel: ViewModel() {
    private val locationLiveData=MutableLiveData<Location>()
    var locationLng=""
    var locationLat=""
    var placeName=""
    val weatherLiveData= Transformations.switchMap(locationLiveData){
        location-> Repository.refreshWeather(location.lng,location.lat)

    }
    fun refreshWeather(lng:String,lat:String){
        LogUtil.i("weatherLiveData","lng:${lng} lat:${lat}")
        locationLiveData.value=Location(lng,lat)

    }
}